package com.aps.server.parse.model;

import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @Author nbZhuozh
 * @Date 2025-09-02  16:12
 *
 * 通用excel 返回结果集
 **/

@Data
public class ExcelImportResult {
    private Class<?> targetClass;

    private String fileName; //文件名称
    public ExcelImportResult(){}

    private long fileSize; //文件大小

    private String fileType;//文件类型

    private String filePath; //todo 文件url

    private long readSize; //读取的行数

    private long successSize; //成功录入行数

    private long errorSize; //失败行数

    private List<?> errorList; //失败的数据

    private String errorExcelDetailsMsg; //失败详情

    private ExcelImportResult(String fileName, long fileSize, String fileType,
                              String filePath, long readSize, long successSize, long errorSize,
                              List<?> errorList, String errorExcelDetailsMsg) {
        this.fileName = fileName;
        this.fileSize = fileSize;
        this.fileType = fileType;
        this.filePath = filePath;
        this.readSize = readSize;
        this.successSize = successSize;
        this.errorSize = errorSize;
        this.errorList = errorList;
        this.errorExcelDetailsMsg = errorExcelDetailsMsg;
    }

    public static ExcelImportResult builder(MultipartFile file , String filePath , int readSize,  int successSize  , List<?> errorList , String errDetailMsg) {
        int errorSize = errorList == null ? 0 : errorList.size();
        return new ExcelImportResult(file.getName(),file.getSize(),file.getContentType(),filePath,readSize,successSize,errorSize,errorList,errDetailMsg);
    }

    public static ExcelImportResult create(MultipartFile file , Class<?> targetClass) {
        ExcelImportResult builder = builder(file, "", 0, 0, null, null);
        builder.setTargetClass(targetClass);
        return builder;
    }
}
